<?php
class Job extends Requester {
	var $iID;
	var $sName;
	var $iStart;
	var $sUrgencies;
	var $oConfig;
	var $sMissiongroups;
	var $oMissions;
	var $sMissionTodos;
	var $sAccess;
	var $iUpdated;
	var $iOwner;
	var $sDescription;
	
	var $iChangers;

	var $iIssueCount;

	var $iJobgroup;

	public function Job($iID = 0, $sName = '', $iStart = 0, $sUrgencies = array(), $iUpdated = 0, $iOwner = 0, $sDescription = '', $iIssueCount = 0, $iJobgroup = 0) {
		$this->iID = $iID;
		$this->sName = $sName;
		$this->iStart = $iStart;
		$this->sUrgencies = $sUrgencies;
		$this->iUpdated = (int)$iUpdated;
		$this->iOwner = (int)$iOwner;
		$this->sDescription = (string)$sDescription;
		$this->iIssueCount = (int)$iIssueCount;
		$this->iJobgroup = (int)$iJobgroup;
	}
	
	public function getMissiongroups() {
		if (!is_array($this->sMissiongroups)) {
			$this->sMissiongroups = JobHandler::getMissiongroups($this->iID);
		}
		
		return $this->sMissiongroups;
	}
	
	public function getMissions($bForceShowHidden = false) {
		return MissionHandler::getMissions($this->iID, $bForceShowHidden);
	}
	
	public function getMissionTodos() {
		if (!is_array($this->sMissionTodos)) {
			$this->sMissionNames = JobHandler::getMissionTodos($this->iID);
		}
		
		return $this->sMissionNames;
	}
	
	public function getConfig() {
		return JobHandler::getConfig($this->iID);
	}
	
	public function getAccessCount($sAccess = 'change')
	{
		$iCount = 0;
		
		if (!is_array($this->sAccess))
			$this->sAccess = JobHandler::getAccess($this->iID);

		foreach ($this->sAccess['usergroups'] as $sThisAccess)
		{
			if ($sThisAccess == $sAccess)
			{
				$iCount++;
			}
		}
		
		foreach ($this->sAccess['users'] as $sThisAccess)
		{
			if ($sThisAccess == $sAccess)
			{
				$iCount++;
			}
		}
		
		return $iCount;
	}

	public function getFiles()
	{
		return JobHandler::getFiles($this->iID);
	}
}
?>
